<!-- 音标专练列表 -->

<template>
	<view class="container">
		<u-navbar title="音标专练" :leftIconSize="0"></u-navbar>
		<view class="list-box">
			<view class="container-list" v-for="item in phoneticPracticeList" :key="item.title">
				<view class="container-list-top">{{item.title}}</view>
				<view class="container-list-bottom">
					<view @click="goDetail(data.versionId)" v-for="data in item.phoneticList" :key="data.id">
						[{{data.symbols}}]</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getPhoneticPracticeList,
	} from '@/api/phoneticPractice'
	export default {
		data() {
			return {
				phoneticPracticeList: []
			}
		},
		onLoad(options) {
			let token = uni.getStorageSync('token')
			if (!token && options && options.token) {
				uni.setStorage({
					key: 'token',
					data: options.token,
					success: function() {
						this.getPhoneticPracticeList();
					}
				});
			} else {
				this.getPhoneticPracticeList();
			}
		},
		methods: {
			onClickLeft() {

			},
			//获取音标列表
			getPhoneticPracticeList() {
				getPhoneticPracticeList().then(res => {
					if (res.code == 1) {
						let phoneticList = []
						for (const key in res.data) {
							phoneticList.push({
								title: key,
								phoneticList: res.data[key]
							})
						}
						this.phoneticPracticeList = phoneticList
					}
				})
			},
			goDetail(versionId) {
				uni.navigateTo({
					url: '/pages/phoneticPractice/detail?versionId=' + versionId
				})
			},
			//返回上一页
			onClickLeft() {
				var u = navigator.userAgent;
				var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
				var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
				if (isAndroid) {
					window.android.goBack();
				} else if (isiOS) {
					window.webkit.messageHandlers.back.postMessage("")
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		// height: 100vh;
		background: #F6F6F6;
		display: flex;
		flex-direction: column;
		align-items: center;

		.list-box {
			margin-top: 44px;
		}

		.container-list {
			margin-top: 10px;
			background: #FFFFFF;
			width: 355px;
			height: 108px;
			display: flex;
			flex-direction: column;
			border-radius: 15px;

			.container-list-top {
				font-size: 16px;
				font-weight: bold;
				margin: 10px 0 0 10px;
				color: #333333;
			}

			.container-list-bottom {
				display: flex;

				view {
					margin-top: 15px;
					margin-left: 10px;
					height: 46px;
					width: 46px;
					border-radius: 10px;
					background: #0CB76C;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 18px;
					color: #FFFFFF;
				}
			}
		}
	}
</style>